local function nsieve(m,isPrime)
   for i = 2,m,1 do
      isPrime[i] = true
   end
   local count = 0

   for i = 2,m,1 do
      if isPrime[i] then
         for k = i+i,m,i do
            isPrime[k] = false
         end
         count = count + 1
      end
   end

   return count
end


local m = 5120000
local flags = {}

io.write( string.format("Primes up to %8d %8d", m, nsieve(m,flags)), "\n")
